package com.gitee.huanminabc.dynamicdb.config;

import com.baomidou.mybatisplus.autoconfigure.MybatisPlusAutoConfiguration;
import com.gitee.huanminabc.dynamicdb.aop.dbswitch.DBSwitchAdvisor;
import com.gitee.huanminabc.dynamicdb.aop.transa.DBTransactionalAspect;
import com.gitee.huanminabc.dynamicdb.common.SpringContextHolder;
import com.gitee.huanminabc.dynamicdb.core.TenantKey;
import com.gitee.huanminabc.dynamicdb.dal.dao.DatasourceManager;
import com.gitee.huanminabc.dynamicdb.data.DataSourceInitialize;
import com.gitee.huanminabc.dynamicdb.data.TenantInitialize;
import com.gitee.huanminabc.dynamicdb.data.YmlDataSourceInitialize;
import com.gitee.huanminabc.dynamicdb.poll.ShareContextTaskPollExecutor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.Primary;

import java.util.concurrent.Executor;

/**
 * @author huanmin
 * @date 2024/1/4
 */
@Configuration
@Import({
        SpringContextHolder.class,
        DynamicDbSpringConfig.class,
        TenantKey.class,
        DynamicDataSourceMybatisConfig.class,
        MybatisPlusAutoConfiguration.class,
        YmlDataSourceInitialize.class,
        DataSourceInitialize.class,
        TenantInitialize.class,
        DBTransactionalAspect.class,
        DatasourceManager.class,
        MybatisPlusConfig.class,
        DBSwitchAdvisor.class

})
public class DynamicDatasourceMainConfig  {

    //覆盖掉系统的默认的线程池
    @Primary
    @Bean
    public Executor shareContextTaskPollExecutor() {
        return new ShareContextTaskPollExecutor();
    }
//
//    @Bean
//    @Order(Integer.MIN_VALUE)
//    public DBSwitchAdvisor dbSwitchAdvisor() {
//        return new DBSwitchAdvisor();
//    }

}
